package com.ricchieri.manage.bean;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import com.ricchieri.bean.FixedReservationBean;
import com.ricchieri.common.BusinessSettings;
import com.ricchieri.model.User;
import com.ricchieri.util.FacesUtil;

@ManagedBean(name = "viewFixedReservationMB")
@ViewScoped
public class ViewFixedReservationManageBean extends CommonFixedReservationManageBean {

	private static final long serialVersionUID = -4431457088573798836L;

	@PostConstruct
	public void init() {
		this.setSelectedUser((User) FacesUtil.getParametersFlash(BusinessSettings.KEY_USER));
		this.setFixedReservationBean((FixedReservationBean) FacesUtil.getParametersFlash(BusinessSettings.KEY_FIX_RESERVATION));
		
		if(this.getSelectedUser() == null || this.getFixedReservationBean() == null) {
			FacesUtil.redirectToNavigationCase(BusinessSettings.SEARCH_RESERVATION);
		}
		
	}

	public String createSameSchedule() {
		FacesUtil.addParametersFlash(BusinessSettings.KEY_USER, getSelectedUser());
		FacesUtil.addParametersFlash(BusinessSettings.KEY_FIX_RESERVATION, getFixedReservationBean());
		FacesUtil.addParametersFlash(BusinessSettings.KEY_ADD_RESERVATION, BusinessSettings.KEY_ADD_RESERVATION_SCHEDULE);
		return BusinessSettings.ADD_RESERVATION;
	}
	
	public String createSameUser() {
		FacesUtil.addParametersFlash(BusinessSettings.KEY_USER, getSelectedUser());
		FacesUtil.addParametersFlash(BusinessSettings.KEY_FIX_RESERVATION, getFixedReservationBean());
		FacesUtil.addParametersFlash(BusinessSettings.KEY_ADD_RESERVATION, BusinessSettings.KEY_ADD_RESERVATION_USER);
		return BusinessSettings.ADD_RESERVATION;
	}
	
}
